package com.jewelry.web.action;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jewelry.common.util.Constants;
import com.jewelry.service.IConfigAttrService;
import com.jewelry.service.ICustomerService;
import com.jewelry.service.IMaterialStoneService;
import com.jewelry.service.IOrdersService;
import com.jewelry.vo.ConfigAttrVO;
import com.jewelry.vo.CustomerVO;
import com.jewelry.vo.MaterialStoneVO;
import com.jewelry.vo.OrdersVO;

public class MaterialStoneAction extends HttpAction {

	private static final long serialVersionUID = -344721847426257696L;

	private static Logger logger = LoggerFactory
			.getLogger(MaterialStoneAction.class);

	private IMaterialStoneService materialStoneService;

	private IConfigAttrService configAttrService;

	private List<ConfigAttrVO> stoneAttrList;

	private List<ConfigAttrVO> colorAttrList;

	private List<ConfigAttrVO> neatnessAttrList;

	private IOrdersService ordersService;

	public IOrdersService getOrdersService() {
		return ordersService;
	}

	public void setOrdersService(IOrdersService ordersService) {
		this.ordersService = ordersService;
	}

	public List<ConfigAttrVO> getColorAttrList() {
		return colorAttrList;
	}

	public void setColorAttrList(List<ConfigAttrVO> colorAttrList) {
		this.colorAttrList = colorAttrList;
	}

	public List<ConfigAttrVO> getNeatnessAttrList() {
		return neatnessAttrList;
	}

	public void setNeatnessAttrList(List<ConfigAttrVO> neatnessAttrList) {
		this.neatnessAttrList = neatnessAttrList;
	}

	public List<ConfigAttrVO> getStoneAttrList() {
		return stoneAttrList;
	}

	public void setStoneAttrList(List<ConfigAttrVO> stoneAttrList) {
		this.stoneAttrList = stoneAttrList;
	}

	public IConfigAttrService getConfigAttrService() {
		return configAttrService;
	}

	public void setConfigAttrService(IConfigAttrService configAttrService) {
		this.configAttrService = configAttrService;
	}

	private int totalCount;

	private MaterialStoneVO materialStone;

	private List<MaterialStoneVO> materialStoneList;
	
	private List<OrdersVO> orderList;
	
	private List<CustomerVO> customerList;
	
	public List<CustomerVO> getCustomerList() {
		return customerList;
	}

	public void setCustomerList(List<CustomerVO> customerList) {
		this.customerList = customerList;
	}

	private ICustomerService customerService;

	public ICustomerService getCustomerService() {
		return customerService;
	}

	public void setCustomerService(ICustomerService customerService) {
		this.customerService = customerService;
	}

	public List<OrdersVO> getOrderList() {
		return orderList;
	}

	public void setOrderList(List<OrdersVO> orderList) {
		this.orderList = orderList;
	}

	public List<MaterialStoneVO> getMaterialStoneList() {
		return materialStoneList;
	}

	public void setMaterialStoneList(List<MaterialStoneVO> materialStoneList) {
		this.materialStoneList = materialStoneList;
	}

	public MaterialStoneVO getMaterialStone() {
		return materialStone;
	}

	public void setMaterialStone(MaterialStoneVO materialStone) {
		this.materialStone = materialStone;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public IMaterialStoneService getMaterialStoneService() {
		return materialStoneService;
	}

	public void setMaterialStoneService(
			IMaterialStoneService materialStoneService) {
		this.materialStoneService = materialStoneService;
	}

	// ==========================================================================

	public String materialStoneAdminMain() {
		if (materialStone == null) {
			materialStone = new MaterialStoneVO();
		}
		try {
			totalCount = materialStoneService
					.getMaterialStoneCount(materialStone);
		} catch (Exception e) {
			logger.error("getMaterialStoneCount error!", e);
		}
		return SUCCESS;
	}

	public String addMaterialStonePage() {
		if (materialStone == null) {
			materialStone = new MaterialStoneVO();
		}
		OrdersVO order = new OrdersVO();
		CustomerVO customer = new CustomerVO();
		//新单
		order.setState(1);
		try {
			stoneAttrList = configAttrService
					.getConfigAttrListByConfigGroup(Constants.STONE_TYPE_COONFIG);
			colorAttrList = configAttrService
					.getConfigAttrListByConfigGroup(Constants.STONE_COLOR_COONFIG);
			neatnessAttrList = configAttrService
					.getConfigAttrListByConfigGroup(Constants.STONE_NEATNESS_COONFIG);
			orderList = ordersService.getOrdersList(order);
			customerList = customerService.getCustomerList(customer);
		} catch (Exception e) {
			logger.error("addMaterialStonePage error!",e);
		}
		materialStone.setMsid(materialStoneService.getMaterialStoneID());
		return SUCCESS;
	}

	public String addingMaterialStone() {
		try{
			materialStoneService.addMaterialStone(materialStone);
			message="来石资料保存成功!";
		}catch(Exception e){
			logger.error("addingMaterialStone error!",e);
			message=Constants.SYSTEM_ERROR_MSG;
		}
		return SUCCESS;
	}

	public String queryMaterialStoneList() {
		if (logger.isDebugEnabled()) {
			logger.debug("start queryMaterialStoneList ... ");
		}
		if (materialStone == null) {
			materialStone = new MaterialStoneVO();
		}
		try {
			stoneAttrList = configAttrService
					.getConfigAttrListByConfigGroup(Constants.STONE_TYPE_COONFIG);
			materialStoneList = materialStoneService
					.getMaterialStoneListByPage(materialStone);
		} catch (Exception e) {
			logger.error("getMaterialStoneListByPage error!", e);
		}
		return SUCCESS;
	}

}
